import _some from "lodash/some";
import _isFunction from "lodash/isFunction";
import createDropField from "./createDropField";
import { DragType } from "../../config";
import { hasTemplate } from "../../utils";
var DropFieldTabsTabPane = createDropField({
  // 接收 左侧 tpl 组件
  dropAcceptTypes: [DragType.dragComponent],
  canDrop: function canDrop(props) {
    var currentEditField = props.currentEditField,
        currentEditComponent = props.currentEditComponent,
        component = props.component; // 只有当当前 TabPane 是 激活状态时 才能 拖入组件

    return currentEditField === component || hasTemplate(_some(component.children, function (child) {
      return hasTemplate(child, currentEditComponent);
    }));
  },
  drop: function drop(props, monitor) {
    // 如果在子组件中已经 drop 了, 这边就不需要继续 drop 了
    if (!monitor.didDrop()) {
      var component = props.component;
      var onAddField = props.onAddField;

      if (_isFunction(onAddField)) {
        onAddField(component, monitor.getItem().component);
      }
    }
  }
});
export default DropFieldTabsTabPane;